package com.aaa.backsystem.controller;

import com.aaa.backsystem.entity.EchartsDataBo;
import com.aaa.backsystem.entity.Result;
import com.aaa.backsystem.entity.Sale;
import com.aaa.backsystem.service.SaleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * fileName:ThresholdController
 * description:阈值设置和统计
 * author:gyc
 * createTime:2020/7/25 20:33
 * version:1.0.0
 */
@Controller
@RequestMapping("/threshold")
public class ThresholdController extends BaseController {

    @Autowired
    private SaleService saleService;

    /**
     * 跳转散装油销售阈值设置
     *
     * @return
     */
    @RequestMapping("toThreshold")
    public String toThreshold() {
        return "SetThreshold/SetThreshold";
    }

    /**
     * 跳转到统计超过阈值的加油站
     *
     * @return
     */
    @RequestMapping("toStat")
    public String toStatThreshold(Model model) {
        List<Sale> buyYear = saleService.findBuyYear(null);
        model.addAttribute("buyYear", buyYear);
        return "statThreshold/statThreshold";
    }

    /**
     * 获取散装油销量纪录
     *
     * @return
     */
    @RequestMapping("/getEchartData")
    @ResponseBody
    public Result getEchartData(String year) {
        try {
            List<EchartsDataBo> echartsDataBoList = saleService.OilMonthlySales(year);

            if (echartsDataBoList != null && echartsDataBoList.size() > 0) {
                return success(echartsDataBoList);
            }

        } catch (Exception e) {
            e.printStackTrace();
        }
        return error();
    }
}
